package com.heima.controller;


import com.heima.common.PageResult;
import com.heima.pojo.Partner;
import com.heima.pojo.dto.PartnerDTO;
import com.heima.pojo.vo.PartnerVO;
import com.heima.service.PartnerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping ("/api/user-service/partner")
@Slf4j
public class PartnerController {
    @Autowired
    PartnerService partnerService;
    //合作商分裂查询
    @GetMapping ("/search")
    public PageResult<PartnerVO> page(PartnerDTO partnerDTO) {
        return partnerService.page(partnerDTO);
    }


    //合作商新增
    @PostMapping
    public Boolean savePartner(@RequestBody PartnerDTO partnerDTO){
        return partnerService.savePartner(partnerDTO);
    }

    //合作商查找（Id）
    @GetMapping("/{id}")
    public PartnerVO getById(@PathVariable Integer id){
        return partnerService.getById(id);
    }

    //合作商修改
    @PutMapping("/{id}")
    public Boolean update(@PathVariable Long id, @RequestBody PartnerDTO partnerDTO){
        return partnerService.update(id, partnerDTO);
    }

    //合作商删除
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Long id){
        log.info("删除合作商: {}", id);
        return partnerService.delete(id);
    }
}
